home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / snz128s / src / fileops.c < prev    next >
C/C++ Source or Header  |  1994-04-13  |  3KB  |  125 lines

  1. /*
  2.     fileops - extended form of file operation functions which
  3.                  convert any '/' seperators in the filename to '\' then call
  4.               the original library functions.
  5.  
  6.                  statx is not mapped in global.h
  7. */
  8.  
  9. /* $Id: FILEOPS.C,v 1.2 1994/02/05 18:46:56 gbj Exp user $ */
  10.  
  11. /*
  12. $Log: FILEOPS.C,v $
  13. // Revision 1.2  1994/02/05  18:46:56  gbj
  14. // Beta release
  15. //
  16. // Revision 1.1  1994/01/30  17:23:24  gbj
  17. // Initial revision
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <unistd.h>
  25.  
  26. static void path2dos(const char *path, char *newpath)
  27. {
  28.     const char *p     = path;
  29.     char *q             = newpath;
  30.     int  sep         = 0;
  31.  
  32.     for ( ; *p; p++) {             /* copy string */
  33.         if ((*q = *p) == '/')    /* translate seperator */
  34.             *q = '\\';                            
  35.         if (*q == '\\') {        /* suppress repeated seperators    */
  36.             if (!sep)
  37.                 q++;
  38.             sep = 1;
  39.         }
  40.         else {
  41.             sep =0;
  42.             q++;
  43.         }
  44.     }
  45.             
  46.     *q = '\0';                    /* string terminator */
  47.  
  48.     return;
  49. }
  50.     
  51.  
  52. FILE *fopenx(const char *name, const char *mode)
  53. {
  54.     char namex[FILENAME_MAX];                    /* buffer for translated str */
  55.  
  56.     path2dos(name, namex);                        /* convert path */
  57.     return fopen(namex, mode);                    /* call fopen function */
  58. }
  59.  
  60. int    removex(const char *name)
  61. {
  62.     char namex[FILENAME_MAX];                    /* buffer for translated str */
  63.  
  64.     path2dos(name, namex);                        /* convert path */
  65.     return remove(namex);                        /* call remove function */
  66. }
  67.  
  68. int    renamex(const char *old, const char *new)
  69. {
  70.     char oldx[FILENAME_MAX];                    /* buffer for translated str */
  71.     char newx[FILENAME_MAX];                    /* buffer for translated str */
  72.  
  73.     path2dos(old, oldx);                        /* convert path */
  74.     path2dos(new, newx);
  75.     return rename(oldx, newx);                    /* call remove function */
  76. }
  77.  
  78. int    openx(const char *name, int mode, int prot)
  79. {
  80.     char namex[FILENAME_MAX];                    /* buffer for translated str  */
  81.  
  82.     path2dos(name, namex);                        /* convert path */
  83.     return open(namex, mode, prot);                /* call open function */
  84. }
  85.  
  86. int    creatx(const char *name, int prot)
  87. {
  88.     char namex[FILENAME_MAX];                    /* buffer for translated str */
  89.  
  90.     path2dos(name, namex);                        /* convert path */
  91.     return creat(namex, prot);                    /* call creat function */
  92. }
  93.  
  94. int    unlinkx(const char *name)
  95. {
  96.     char namex[FILENAME_MAX];                    /* buffer for translated str */
  97.  
  98.     path2dos(name, namex);                        /* convert path */
  99.     return unlink(namex);                        /* call unlink function */
  100. }
  101.  
  102. int    accessx(const char *name, int mode)
  103. {
  104.     char namex[FILENAME_MAX];                    /* buffer for translated str */
  105.  
  106.     path2dos(name, namex);                        /* convert path */
  107.     return access(namex, mode);                    /* call remove function */
  108. }
  109.     
  110. int    mkdirx(const char *path)
  111. {
  112.     char pathx[FILENAME_MAX];                    /* buffer for translated str */
  113.  
  114.     path2dos(path, pathx);                        /* convert path */
  115.     return mkdir(pathx, 0);                        /* call mkdir function */
  116. }
  117.  
  118. int    statx(const char *path, struct stat *statbuf)
  119. {
  120.     char pathx[FILENAME_MAX];
  121.  
  122.     path2dos(path, pathx);
  123.     return stat(pathx, statbuf);
  124. }
  125.